package com.netease.nie.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.netease.nie.base.controllers.BaseController;
import com.netease.nie.base.exceptions.BusinessException;
import com.netease.nie.constants.BusinessConstants;
import com.netease.nie.dto.RobbedGoodsDto;
import com.netease.nie.facade.RobGoodsFacade;

@RestController
@RequestMapping("/api/user")
public class RobController extends BaseController {

	@Autowired
	private RobGoodsFacade robGoodsFacade;

	@RequestMapping(value = "/robbed_list", method = RequestMethod.GET, produces = "application/json")
	public String robbedList(HttpServletRequest request, Integer page,
			Integer type) throws Exception {
		Long userId = (Long) request.getAttribute("userId");

		if (userId == null)
			throw new BusinessException(
					BusinessConstants.USER_NOT_LOGIN.getCode(), "用户未登录");
		if (userId <= 0)
			throw new BusinessException(
					BusinessConstants.INVALID_USER_ID.getCode(), "用户id不合法");

		if (type == null)
			type = 0;

		if (page == null)
			page = 1;
		List<RobbedGoodsDto> robGoodsDtoList = robGoodsFacade
				.queryRobbedGoodsDtoListByConditon(userId, type, page);
		return jsonSuccess(robGoodsDtoList);
	}

}
